//package com.auth.authserver.exception;
//
//import com.auth.authserver.utils.JwtUtils;
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.util.HashMap;
//import java.util.Map;
//
//
///**
// * 第二种方式
// *
// * @author Json
// * @date 2021/11/8 15:33
// */
//@Component
//public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
//
//    @Override
//    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException {
//        httpServletResponse.setContentType("application/json;charset=utf-8");
//        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
//        PrintWriter out = httpServletResponse.getWriter();
//        Map<String, Object> map = new HashMap<String, Object>(4);
//        String jwt = JwtUtils.createJwt("admin");
//        httpServletResponse.addHeader("Authorization",  jwt);
//        map.put("code", HttpServletResponse.SC_OK);
//        map.put("message", "登陆成功！");
//        map.put("token",jwt);
//        out.write(new ObjectMapper().writeValueAsString(map));
//        out.flush();
//        out.close();
//    }
//}
